#version 150

in  vec2 texCoord;
out vec4 fColor;

uniform sampler2D texture;

float T = 0.1;

void main() 
{ 
	ivec2 ires = textureSize(texture,0);
	float ResS = float(ires.s);
	float ResT = float(ires.t);
	vec3 irgb = texture2D(texture, texCoord).rgb;

	vec2 stp0 = vec2(1./ResS, 0.);
	vec2 stpp = vec2(1./ResS, 1./ResT);
	vec3 c00 = texture2D(texture, texCoord).rgb;
	vec3 cp1p1 = texture2D(texture, texCoord+stpp).rgb;

	vec3 diffs = c00 - cp1p1;
	float max = diffs.r;
	if(abs(diffs.g)>abs(max))
	{
		max = diffs.g;
	}
	if(abs(diffs.b)>abs(max))
	{
		max = diffs.b;
	}

	float gray = clamp(max+.5, 0.,1.);
	vec4 grayVersion = vec4(gray, gray, gray,1.);
	vec4 colorVersion = vec4(gray*c00,1.);
	
	fColor = mix(grayVersion, colorVersion, T);
}